package com.flyduck.modules.system.service.impl;

import com.flyduck.modules.system.domain.SysLog;
import com.flyduck.modules.system.mapper.SysLogMapper;
import com.flyduck.modules.system.service.SysLogService;
import com.flyduck.common.vo.PageResult;
import com.flyduck.common.vo.QueryVo;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @program: flyduck-admin
 * @description:
 * @author: flyduck
 * @create: 2020-05-29 17:00
 **/
@Service
public class SysLogServiceImpl implements SysLogService {

    @Autowired
    private SysLogMapper sysLogMapper;

    /**
     * 根据日志id删除日志
     * @param id
     */
    @Override
    public void deleteById(Long id) {
        sysLogMapper.deleteByPrimaryKey(id);
    }

    /**
     * 根据id查询日志
     * @param id
     * @return
     */
    @Override
    public SysLog getLogById(Long id) {
        return sysLogMapper.selectByPrimaryKey(id);
    }

    /**
     * 首页数据
     * @param queryVo
     * @return
     */
    @Override
    public PageResult findPage(QueryVo queryVo) {
        //分页查询
        PageHelper.startPage(queryVo.getPage(),queryVo.getRows());
        Page<SysLog> sysLogPage = sysLogMapper.findPage(queryVo.getKeyword());
        //分页结果集
        PageResult pageResult = new PageResult();
        pageResult.setTotal(sysLogPage.getTotal());
        pageResult.setRows(sysLogPage.getResult());
        return pageResult;
    }
}
